package com.shunwang.errors.engine.util;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ClazzUtil {

	public static Class getClass(String className) throws ClassNotFoundException{
		return Class.forName(className);
	}
	
	public static Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException{
		return newInstance(getClass(className));
	}
	
	public static Object newInstance(Class clazz) throws InstantiationException, IllegalAccessException{
		return clazz.newInstance();
	}
	
	public static Method[] getMethod(Class clazz){
		return clazz.getDeclaredMethods();
	}
	
	public static Method[] getMethod(String className) throws SecurityException, ClassNotFoundException{
		return getMethod(getClass(className));
	}
	
	public static Method getMethod(Class clazz,String methodName,Class[] paramClazz) throws SecurityException, NoSuchMethodException{
		return clazz.getMethod(methodName, paramClazz);
	}
	
	public static Method getMethod(String className,String methodName,Class[] paramClazz) throws SecurityException, NoSuchMethodException, ClassNotFoundException{
		return getMethod(getClass(className),methodName,paramClazz);
	}
	
	public static Field[] getField(Class clazz){
		return clazz.getDeclaredFields();
	}
	
	public static Field[] getField(String className) throws ClassNotFoundException{
		return getField(getClass(className));
	}
	
	public static Field getField(Class clazz,String fieldName) throws SecurityException, NoSuchFieldException{
		return clazz.getField(fieldName);
	}
	
	public static Field getField(String clazzName,String fieldName) throws SecurityException, NoSuchFieldException, ClassNotFoundException{
		return getField(getClass(clazzName),fieldName);
	}
}
